// JavaScript Document

var datavalues = Array();
var xmlhttp=false;

function getxmlhttp()
{
	var _xmlhttp=false;
	
	try 
	{
  		_xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	} catch (e) 
 	{
  		try 
  		{
   		_xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  		} catch (E) 
  		{
   		_xmlhttp = false;
  		}
 	}
	if(!_xmlhttp && typeof XMLHttpRequest!='undefined') 
	{
  		_xmlhttp = new XMLHttpRequest();
	}
	return _xmlhttp;
}


function updatesearch(page)
{
	//alert (page);
	if(xmlhttp && xmlhttp.readyState!=0)
	{
	  xmlhttp.abort()
	}
	xmlhttp=getxmlhttp();
  
	timer = setTimeout(function () 
 	{
 		xmlhttp.abort();
 		document.body.style.cursor = "default";
 		document.getElementById("searchdata").innerHTML="<div class=\"searchmessage\"><b>Query Timed Out</b><br>Either your query was too broad (particularly with location queries) or the server is busy. Please try again later.</div>";
  	},10000);
  	if(xmlhttp)
  	{
  		var theurl = "ajax_canmua.php?which_page="+page;
		
		for (var i in datavalues)
		{
			theurl+='&'+i+"="+urlencode(datavalues[i]);	
			//theurl+='&'+i+"="+datavalues[i];	
		}
		alert (theurl);

  		xmlhttp.open("GET",theurl,true);
  		document.body.style.cursor = "progress";
  		xmlhttp.onreadystatechange=function() 
  		{
  			if(xmlhttp.readyState==4) 
  			{
  				clearTimeout(timer);
  	    		if(xmlhttp.status==200)
     			{	
     				document.getElementById("searchdata").innerHTML=xmlhttp.responseText;
     				
     							
     			} else
     			{
					//document.getElementById("searchdata").innerHTML="loi " + page;	
     			}
  				document.body.style.cursor = "default";
     		}	
		}
		xmlhttp.send(null);
	}
}

function urlencode(str) 
{
	str = escape(str);
	str = str.replace('+', '%2B');
	str = str.replace('%20', '+');
	str = str.replace('*', '%2A');
	str = str.replace('/', '%2F');
	str = str.replace('@', '%40');
	return str;
}
function urldecode(str) {
str = str.replace('+', ' ');
str = unescape(str);
return str;
}